<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <button id="btn">111</button>
    <script>
        // Object.defineProperty版本
        function execute(ele,type) {
            let arr = [];
            let fn;
            fn = ele[type] = function (e) {
                arr.forEach(fn => {
                    fn(e);
                });
            }
            Object.defineProperty(ele, type, {
                set(newV) {
                    arr.push(newV);
                },
                get(){
                    return fn;
                }
            })
        }
        
        execute(btn, 'onclick');
        btn.onclick = function (e) {
            console.log(1,e);
        }
        btn.onclick = function (e) {
            console.log(2,e);
        }
        btn.onclick = function (e) {
            console.log(3,e);
        }
        btn.onclick = function (e) {
            console.log(4,e);
        }
        // 柯里化版本
    //     function curryConfig (dom,type) {
    //             let _args = [];
    //             dom[type] = function (e) {
    //                 _args.forEach(fn => {
    //                     fn(e);
    //                 })
    //             }
    //             let inner = function (fn) {
    //                 _args.push(fn);
    //                 return inner;
    //             }
    //             return inner;
    //     }
    //     curryConfig(btn,'onclick')(function(){
    //        console.log('111')
    //    })(function(){
    //         console.log(22);
    //    })(function() {
    //        console.log(333);
    //    })
    </script>
</body>

</html>